from rest_framework import serializers
from users.models import User


class UsersModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'

        extra_kwargs = {
            'password': {
                'write_only': True
            }
        }

    def create(self, validated_data):

        try:
            instance = User.objects.create_user(**validated_data)
        except TypeError as msg:
            raise TypeError(msg)

        return instance

